package TOOLS.setupTable;

public class ibee {
	comPortTool comPort=new comPortTool();
	public ibee(String icom) throws Exception {
		comPort.OpenPort("COM"+icom, 9600,2);
	}
	
	public ibee(String icom,int baudrate,int jiaoyan) throws Exception {
		comPort.OpenPort("COM"+icom, baudrate,jiaoyan);
	}
	
	public void putLightOff() throws Exception {
		String str="01 05 00 00 00 00 CD CA";
		byte [] od=StringToByteArray(str);
		comPort.sendToPort(od);
	}
	
	public void passLight() throws Exception {
		putLightOff();
		String str="01 05 00 03 FF 00 7C 3A";
		byte [] od=StringToByteArray(str);
		comPort.sendToPort(od);
	}
	
	public void failLight() throws Exception {
		putLightOff();
		String str="01 05 00 0A FF 00 AC 38";
		byte [] od=StringToByteArray(str);
		comPort.sendToPort(od);
	}
	
	public static byte[] StringToByteArray(String idata) {
		String [] adata=idata.split(" ");
		byte [] odata=new byte[adata.length];
		String str="";
		for(int i=0;i<adata.length;i++) {
			str=adata[i];
			if(str==null || str.length()<1) {
				str="00";
			}else if(str.length()<2){
				str="0"+str;
			}else if(str.length()>2) {
				str=str.substring(0, 2);
			}
			odata[i]=(byte)Integer.parseInt(str, 16);
		}
		return odata;
	}
}
